﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NutriLeaf.Web.Core.NutritionInfo
{
    public class NutritionInfo:INutritionInfo
    {
        public void AddNutritionInfo(Model.NutritionInfo nutrition, ref Model.NutriLeafDBEntities context)
        {
            context.NutritionInfoes.AddObject(nutrition);
            context.SaveChanges();
        }

        public void RemoveNutritionInfo(int id, ref Model.NutriLeafDBEntities context)
        {
          context.DeleteObject(context.NutritionInfoes.Where(p=>p.NutritionInfoID==id).First());
          context.SaveChanges();
        }

        public void RemoveNutritionInfo(Model.NutritionInfo nutrition, ref Model.NutriLeafDBEntities context)
        {
            context.NutritionInfoes.DeleteObject(context.NutritionInfoes.Where(p => p.NutritionInfoID == nutrition.NutritionInfoID).First());
            context.SaveChanges();
        }

        public Model.NutritionInfo GetNutritionInfo(int id, ref Model.NutriLeafDBEntities context)
        {
            return context.NutritionInfoes.Where(p => p.NutritionInfoID == id).First();
        }

        public void Update(Model.NutritionInfo nutrition, ref Model.NutriLeafDBEntities context)
        {
            Model.NutritionInfo info = context.NutritionInfoes.Where(p => p.NutritionInfoID == nutrition.NutritionInfoID).First();
            info = nutrition;
            context.SaveChanges();
        }
    }
}